package com.ppp.poi.common;

import com.google.common.collect.ImmutableMap;
import com.ppp.poi.bean.entity.User;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author Wu Jin
 * @create 2020-01-19
 */
public interface AppConstant {

  ThreadLocal<Map<String, Object>> contextLocal = new ThreadLocal<>();

  static void add(String key, Object val) {
    Map<String, Object> m = contextLocal.get();
    if (m == null) {
      m = new LinkedHashMap<>();
      contextLocal.set(m);
    }
    m.put(key, val);
  }

  static Object get(String key) {
    Map<String, Object> map = contextLocal.get();
    return map == null ? null : map.get(key);
  }

  static User getCurrentUser() {
    return (User) get("user");
  }

  static void remove() {
    contextLocal.remove();
  }

  static Map<String, Object> getContext() {
    return contextLocal.get();
  }

  String METHOD_SUCCESS = "Y";

  String METHOD_FAIL = "N";

  String LOG_SPLIT = "^|";


  String DISTRICT_URL_BASE = "https://restapi.amap.com/v3/config/district";

  String DISTRICT_URL = DISTRICT_URL_BASE + "?key=%s&keywords=%s&subdistrict=3&extensions=all";

  String KEYWORD_URL = "https://restapi.amap.com/v3/place/text";

  /**
   * 多边形搜索
   * <pre>
   *
   * </pre>
   */
  String POLIYGON_URL_BASE = "http://restapi.amap.com/v3/place/polygon";

  /**
   * key,types,keywords,polygon
   */
  String POLIYGON_URL = POLIYGON_URL_BASE + "?key=%s&types=%s&keywords=%s&output=json&extensions=all";

  String AROUND_URL = "https://restapi.amap.com/v3/place/around";

  String POI_URL = "http://restapi.amap.com/v3/place/text?key=%s&extensions=all&keywords=%s&city=%s";

  Map<String, String> HEADER_DICT = ImmutableMap.<String, String>builder()
      .put("唯一ID", "id")
      .put("POI名称", "name")
      .put("POI类型", "type")
      .put("POI类型编号", "typecode")
      .put("行业类型", "biz_type")
      .put("地址", "address")
      .put("经度", "lng")
      .put("纬度", "lat")
      .put("POI所在省份名称", "pname")
      .put("POI所在城市名称", "cityname")
      .put("区域编码", "adname")
      .put("商家电话", "tel")
      .put("店铺评分", "rating")
      .put("人均消费", "cost")
      .put("口味评分", "taste_rating")
      .put("环境评分", "environment_rating")
      .put("服务评分", "service_rating")
      .build();

  Map<String, String> HEADER_DICT_TRANS = ImmutableMap.<String, String>builder()
      .put("header01", "id")
      .put("header02", "name")
      .put("header03", "type")
      .put("header04", "typecode")
      .put("header05", "biz_type")
      .put("header06", "address")
      .put("header07", "lng")
      .put("header08", "lat")
      .put("header09", "pname")
      .put("header10", "cityname")
      .put("header11", "adname")
      .put("header12", "tel")
      .put("header13", "rating")
      .put("header14", "cost")
      .put("header15", "taste_rating")
      .put("header16", "environment_rating")
      .put("header17", "service_rating")
      .build();

  Map<String, String> HEADER_DICT_2 = ImmutableMap.<String, String>builder()
      .put("header01", "唯一ID")
      .put("header02", "POI名称")
      .put("header03", "POI类型")
      .put("header04", "POI类型编号")
      .put("header05", "行业类型")
      .put("header06", "地址")
      .put("header07", "经度")
      .put("header08", "纬度")
      .put("header09", "POI所在省份名称")
      .put("header10", "POI所在城市名称")
      .put("header11", "区域编码")
      .put("header12", "商家电话")
      .put("header13", "店铺评分")
      .put("header14", "人均消费")
      .put("header15", "口味评分")
      .put("header16", "环境评分")
      .put("header17", "服务评分")
      .build();

  Map<String, String> TYPE_DICT = ImmutableMap.<String, String>builder()
      .put("汽车服务", "010000")
      .put("汽车销售", "020000")
      .put("汽车维修", "030000")
      .put("摩托车服务", "040000")
      .put("餐饮服务", "050000")
      .put("购物服务", "060000")
      .put("生活服务", "070000")
      .put("体育休闲服务", "080000")
      .put("医疗保健服务", "090000")
      .put("住宿服务", "100000")
      .put("风景名胜", "110000")
      .put("商务住宅", "120000")
      .put("政府机构及社会团体", "130000")
      .put("科教文化服务", "140000")
      .put("交通设施服务", "150000")
      .put("金融保险服务", "160000")
      .put("公司企业", "170000")
      .put("道路附属设施", "180000")
      .put("地名地址信息", "190000")
      .put("公共设施", "200000")
      .put("事件活动", "220000")
      .put("室内设施", "970000")
      .put("通行设施", "990000")
      .build();

  Map<String, String> TYPE_DICT_TRANS = ImmutableMap.<String, String>builder()
      .put("type01", "010000")
      .put("type02", "020000")
      .put("type03", "030000")
      .put("type04", "040000")
      .put("type05", "050000")
      .put("type06", "060000")
      .put("type07", "070000")
      .put("type08", "080000")
      .put("type09", "090000")
      .put("type10", "100000")
      .put("type11", "110000")
      .put("type12", "120000")
      .put("type13", "130000")
      .put("type14", "140000")
      .put("type15", "150000")
      .put("type16", "160000")
      .put("type17", "170000")
      .put("type18", "180000")
      .put("type19", "190000")
      .put("type20", "200000")
      .put("type21", "220000")
      .put("type22", "970000")
      .put("type23", "990000")
      .build();


  String WECHAT_AUTH_URL = "https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=authorization_code";
}
